Add GetPartialObject to MTP example#3641
Merged
Merged
Conversation
Added support for GetPartialObject for better compatibility with Linux file explorers.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for the MTP GetPartialObject operation in the MTP device example so that Linux file managers (which prefer partial reads) can open files directly from the MTP drive, matching existing behavior on Windows (which uses GetObject).
Changes:
- Register
MTP_OP_GET_PARTIAL_OBJECTin the supported operations list intusb_config.h. - Add
fs_get_partial_objecthandler that mirrorsfs_get_objectbut honors host-supplied offset/max-length parameters. - Handle response building for
MTP_OP_GET_PARTIAL_OBJECTintud_mtp_data_complete_cb, returning the actual number of bytes sent.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| examples/device/mtp/src/tusb_config.h | Adds MTP_OP_GET_PARTIAL_OBJECT to the list of supported MTP operations. |
| examples/device/mtp/src/mtp_fs_example.c | Registers the new handler in the dispatch table, implements fs_get_partial_object, and adds the corresponding response case in tud_mtp_data_complete_cb. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
| target | .text | .rodata | .data | .bss | total | % diff |
|---|---|---|---|---|---|---|
| raspberrypi_zero/mtp | 60,104 → 61,512 (+1,408) | 4,651 → 7,339 (+2,688) | 17,072 → 17,080 (+8) | — | 94,123 → 98,227 (+4,104) | +4.4% |
| msp_exp430f5529lp/mtp | 15,724 → 16,376 (+652) | — | 324 → 330 (+6) | — | 24,660 → 25,324 (+664) | +2.7% |
| lpcxpresso11u37/mtp | 16,128 → 16,496 (+368) | — | 372 → 380 (+8) | — | 22,868 → 23,252 (+384) | +1.7% |
| mm900evxb/mtp | 26,344 → 26,952 (+608) | — | 3,700 → 3,716 (+16) | — | 39,116 → 39,756 (+640) | +1.6% |
| nutiny_nuc126v/mtp | 17,012 → 17,380 (+368) | — | 400 → 408 (+8) | — | 23,512 → 23,896 (+384) | +1.6% |
| raspberry_pi_pico/mtp | 19,656 → 20,032 (+376) | — | — | — | 23,244 → 23,620 (+376) | +1.6% |
| fomu/mtp | 23,920 → 24,512 (+592) | — | — | — | 38,304 → 38,912 (+608) | +1.6% |
| nutiny_sdk_nuc121/mtp | 17,028 → 17,380 (+352) | — | 400 → 408 (+8) | — | 23,528 → 23,896 (+368) | +1.6% |
| nutiny_sdk_nuc120/mtp | 17,608 → 17,960 (+352) | — | 432 → 440 (+8) | — | 24,144 → 24,512 (+368) | +1.5% |
| lpcxpresso51u68/mtp | 18,264 → 18,616 (+352) | — | 376 → 384 (+8) | — | 24,660 → 25,028 (+368) | +1.5% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently MTP example works fine under Windows, but Linux file explorers had problems with opening files directly from MTP drive. Copying entire file to local drive was working though.
This is most likely due to fact that Windows uses GetObject to read entire file in one transfer and Linux tries to use GetPartialObject which is not implemented in this example.
This PR fixes this problem by implementing GetPartialObject handler. Implementation is very similar to existing GetObject, but takes file offset from host into the account.
I successfully tested it on stm32f411blackpill and stm32h503nucleo under Linux Mint (command line file access and Nemo file explorer). RAM usage increased by 8 bytes, FLASH usage increased by 200 bytes on STM32H503.